#include<stdio.h>
#include<unistd.h> 
#include<sys/types.h>
#include<sys/wait.h>
#include<stdlib.h>

int main()
{
  printf("my process begin...\n");
  pid_t id = fork();
  
  if(id == 0)//child
  {
    printf("running, I am child,pid:%d\n",getpid());
    execl("/usr/bin/pwd","pwd",NULL);
    printf("end...\n");
    exit(123);
  }
  else if(id > 0)//parent
  {
    printf("running, I am father, pid:%d\n",getpid());
    
    int status = 0;
    pid_t ret = waitpid(id,&status,0);
    if(ret > 0)
    {
      //等待成功，ret是子进程id
      printf("father waits for  success,ret:%d,exitcode:%d,sign:%d\n",
          ret, (status>>8)&0xff,status&0x7f);
    }
    else 
    {
      printf("father wait failed!\n");
    }
  }
  else  
  {
      printf("fork failed!\n");
  }

  return 0;
}
